// pages/test/myTest.js
const app = getApp()
var util = require("../../../utils/pageChangeUtils")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    switchFlag: false,
    submit: "",
    mark: "",
    marked: "",
    markedFlag: false,
    flagArr: [],
    index: 0
  },

  mark: function () {
    let title1 = this.selectComponent("#title1")
    this.data.flagArr[this.data.index] = !this.data.flagArr[this.data.index]
    //这里将本题做标记
    this.setData({
      markedFlag: !this.data.markedFlag,
      flagArr: this.data.flagArr
    })
  },

  zuJianTongXin: function (e) {
    let title1 = this.selectComponent("#title1")
    if (e.detail.type == "lastQuestion") { //触发下一道问题
      title1._lastQuestion()
    }
    if (e.detail.type == "nextQuestion") { //触发下一道问题
      title1._nextQuestion()
    }
    if (e.detail.type == "bindPickerChange") { //直接设置题目
      title1._bindPickerChange(e.detail.a)
    }
    var index = e.detail.a
    this.setData({
      index: index
    })
  },

  zuJianTongXin2: function (e) {
    this.setData({
      index: e.detail
    })
    let buttom1 = this.selectComponent("#buttom1")
    buttom1.setData({
      index: e.detail
    })
  },

  submit: function () {
    const title1 = this.selectComponent("#title1")
    var flagArr = this.data.flagArr
    var items = []
    for (let i = 0; i < flagArr.length; i++) {
      if (flagArr[i]) {
        items.push(i)
      }
    }
    if (items.length > 0) { //表示还有题目做了标记
      title1._submit({
        confirm: false,
        flagArr: items[0]
      })
    } else {
      title1._submit({
        confirm: true
      })
    }
  },





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: app.globalData.selectLib
    })
    let that = this
    let selectLib = app.globalData.selectLib
    let testItem = wx.getStorageSync('testItem')
    util.findTestItem(selectLib, testItem).then(res => {
      let flagArr = new Array()
      for (let i = 0; i < res.items; i++) {
        flagArr[i] = false
      }
      let cacheImage = wx.getStorageSync('image')
      that.setData({
        submit: cacheImage.testCss[0],
        mark: cacheImage.testCss[1],
        marked: cacheImage.testCss[4],
        flagArr: flagArr
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})